#!/bin/bash
# Startup script for EulerOS IPV4 #

echo "app_instance_id_key=($$APP_INSTANCE_ID)" >> /home/init.txt

rm -f /etc/sysconfig/network-scripts/*ifcfg-e*
rm -f /etc/sysconfig/network-scripts/*route-e*
netname1=`ip a | grep '^2:' | awk -F ':' '{print $2}'|sed 's/^[ \t]*//g'`
netname2=`ip a | grep '^3:' | awk -F ':' '{print $2}'|sed 's/^[ \t]*//g'`
netname3=`ip a | grep '^4:' | awk -F ':' '{print $2}'|sed 's/^[ \t]*//g'`

echo "BOOTPROTO=static" >> /etc/sysconfig/network-scripts/"ifcfg-${netname2}"
echo "DEVICE=${netname2}" >> /etc/sysconfig/network-scripts/"ifcfg-${netname2}"
echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/"ifcfg-${netname2}"
echo "TYPE=Ethernet" >> /etc/sysconfig/network-scripts/"ifcfg-${netname2}"
echo "USERCTL=no" >> /etc/sysconfig/network-scripts/"ifcfg-${netname2}"
echo "DEFROUTE=yes" >> /etc/sysconfig/network-scripts/"ifcfg-${netname2}"
echo "IPV4_FAILURE_FATAL=no" >> /etc/sysconfig/network-scripts/"ifcfg-${netname2}"
echo "MTU=1500" >> /etc/sysconfig/network-scripts/"ifcfg-${netname2}"
echo "IPADDR=$APP_Public_IP$" >> /etc/sysconfig/network-scripts/"ifcfg-${netname2}"
echo "NETMASK=$APP_Public_MASK$" >> /etc/sysconfig/network-scripts/"ifcfg-${netname2}"
echo "GATEWAY=$APP_Public_GW$" >> /etc/sysconfig/network-scripts/"ifcfg-${netname2}"

echo "BOOTPROTO=static" >> /etc/sysconfig/network-scripts/"ifcfg-${netname3}"
echo "DEVICE=${netname3}" >> /etc/sysconfig/network-scripts/"ifcfg-${netname3}"
echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/"ifcfg-${netname3}"
echo "TYPE=Ethernet" >> /etc/sysconfig/network-scripts/"ifcfg-${netname3}"
echo "USERCTL=no" >> /etc/sysconfig/network-scripts/"ifcfg-${netname3}"
echo "DEFROUTE=no" >> /etc/sysconfig/network-scripts/"ifcfg-${netname3}"
echo "IPV4_FAILURE_FATAL=no" >> /etc/sysconfig/network-scripts/"ifcfg-${netname3}"
echo "MTU=1500" >> /etc/sysconfig/network-scripts/"ifcfg-${netname3}"
echo "IPADDR=$APP_Private_IP$" >> /etc/sysconfig/network-scripts/"ifcfg-${netname3}"
echo "NETMASK=$APP_Private_MASK$" >> /etc/sysconfig/network-scripts/"ifcfg-${netname3}"

echo "$UE_IP_SEGMENT$ via $APP_Private_GW$" >> /etc/sysconfig/network-scripts/"route-${netname3}"
echo "$ENTERPRISE_CAMPUS$ via $APP_Private_GW$" >> /etc/sysconfig/network-scripts/"route-${netname3}"

echo "BOOTPROTO=static" >> /etc/sysconfig/network-scripts/"ifcfg-${netname1}"
echo "DEVICE=${netname1}" >> /etc/sysconfig/network-scripts/"ifcfg-${netname1}"
echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/"ifcfg-${netname1}"
echo "TYPE=Ethernet" >> /etc/sysconfig/network-scripts/"ifcfg-${netname1}"
echo "USERCTL=no" >> /etc/sysconfig/network-scripts/"ifcfg-${netname1}"
echo "DEFROUTE=no" >> /etc/sysconfig/network-scripts/"ifcfg-${netname1}"
echo "IPV4_FAILURE_FATAL=no" >> /etc/sysconfig/network-scripts/"ifcfg-${netname1}"
echo "MTU=1500" >> /etc/sysconfig/network-scripts/"ifcfg-${netname1}"
echo "IPADDR=$APP_MP1_IP$" >> /etc/sysconfig/network-scripts/"ifcfg-${netname1}"
echo "NETMASK=$APP_MP1_MASK$" >> /etc/sysconfig/network-scripts/"ifcfg-${netname1}"

systemctl restart network